package router

import (
	orig_handler "octopus/internal/delivery/handler"
	"octopus/internal/infrastructure/docker_adapter"
	"octopus/internal/usecase/task_usecase"
	"octopus/internal/usecase/container_usecase"

	"github.com/gin-gonic/gin"
)

func NewRouter() *gin.Engine {
	r := gin.Default()

	repo := docker_adapter.NewDockerContainerRepository()
	taskManager := task_usecase.NewDefaultTaskManager()
	// 设置事件总线
	taskManager.SetEventBus(orig_handler.NewWebSocketEventHandler())

	service := container_usecase.NewContainerService(repo, taskManager)
	handler := orig_handler.NewContainerHandler(service)

	api := r.Group("/api")
	{
		api.GET("/ws", orig_handler.WebSocketHandler) // WebSocket 路由
		api.GET("/containers", handler.ListContainers)
		api.POST("/containers/:id/stop", handler.StopContainer)
		api.POST("/containers/:id/restart", handler.RestartContainer)
	}

	return r
}